< previous page page_93 next page >

Page 93
z0113-01.gif
Figure 3.4
Mapping palette entries to color values.
color for the pixel. In either case, some of the colors displayed on the screen may not be exactly the colors you want.
In an attempt to improve this situation, Windows provides logical palettes in addition to the system palette. Images such as those in forms and picture boxes can all have their own logical palette. When an image receives the input focus, Windows copies entries from the image's logical palette into the system palette in a process known as realizing the palette. The logical palette that is mapped into the system palette first is called the foreground palette.
If the logical palette contains more colors than the system palette, Windows matches the extra colors in the logical palette to the entries in the system palette that are closest. For example, suppose a logical palette contains 300 entries, but the system palette contains only 256. The system palette fills before all of the logical palette's colors have been added.
Suppose the system palette becomes full, and the next color in the logical palette is dark pink. This color may be mapped to pure red if that is the closest match in this system palette. Any pixels that are dark pink in the image are seen as red on the display.
If the logical palette holds fewer entries than the system palette, Windows fills the remaining system palette entries with colors requested by other programs. The palettes of these other programs are called background palettes. Windows continues to add colors to the system palette until all the background palettes are satisfied or the system palette is full.
Finally, Windows matches any remaining colors to whatever values in the system palette are closest. As a result, background images can look strange. If the foreground palette fills the system palette with shades of blue, for example, a picture that uses reds and oranges will not map closely into the system palette.
To make an already confusing situation almost incomprehensible, recent versions of Visual Basic have intruded into the domain of color palettes. Visual Basic forms now have Palette and PaletteMode properties that are supposed to help referee palette use within your application.
The Palette property is a picture that contains the palette the form should use. This need not be the palette required by the images displayed on the form, so it can produce some very unsatisfying results.

 
< previous page page_93 next page >